/*
 * 软件版权: 恒生电子股份有限公司
 * 修改记录:
 * 修改日期     修改人员  修改说明
 * ========    =======  ============================================
 * 2021/4/8  lisy31662  新增
 * ========    =======  ============================================
 */
package com.sansi.pencilbook.service.impl;

import com.sansi.pencilbook.DO.Result;
import com.sansi.pencilbook.entity.Order;
import com.sansi.pencilbook.mapper.OrderMapper;
import com.sansi.pencilbook.service.OrderServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 功能说明: 订单服务实现
 *
 * @author lisy31662
 */
@Service
public class OrderServerImpl implements OrderServer {

  @Autowired
  private OrderMapper orderMapper;

  @Override
  public Result addOrders(List<Order> orders) {
    try{
      int num = orderMapper.saveOrders(orders);
      return num>0 ? Result.ofSuccess("插入订单信息成功", num) :
          Result.ofFailed("插入订单信息失败");
    } catch (Exception throwables) {
      System.out.println(throwables.getMessage());
      return Result.ofFailed(throwables.getMessage());
    }
  }

  @Override
  public Result getOrdersAll() {
    try{
      List<Order> list = orderMapper.findOrdersAll();
      return list.size()>0 ? Result.ofSuccess("获取订单信息成功", list.size(), list) :
          Result.ofFailed("获取订单信息失败");
    } catch (Exception throwables) {
      System.out.println(throwables.getMessage());
      return Result.ofFailed(throwables.getMessage());
    }
  }

  @Override
  public Result getOrdersBySerial(String serialNo) {
    try{
      List<Order> list = orderMapper.findOrdersBySerial(serialNo);
      return list.size()>0 ? Result.ofSuccess("获取订单信息成功", list.size(), list) :
          Result.ofFailed("获取订单信息失败");
    } catch (Exception throwables) {
      System.out.println(throwables.getMessage());
      return Result.ofFailed(throwables.getMessage());
    }
  }

  @Override
  public Result getOrdersByUser(int userId) {
    try{
      List<Order> list = orderMapper.findOrdersByUser(userId);
      return list.size()>0 ? Result.ofSuccess("获取订单信息成功", list.size(), list) :
          Result.ofFailed("获取订单信息失败");
    } catch (Exception throwables) {
      System.out.println(throwables.getMessage());
      return Result.ofFailed(throwables.getMessage());
    }
  }

  @Override
  public Result getOrdersByStore(int storeId) {
    try{
      List<Order> list = orderMapper.findOrdersByStore(storeId);
      return list.size()>0 ? Result.ofSuccess("获取订单信息成功", list.size(), list) :
          Result.ofFailed("获取订单信息失败");
    } catch (Exception throwables) {
      System.out.println(throwables.getMessage());
      return Result.ofFailed(throwables.getMessage());
    }
  }

  @Override
  public Result modifyOrder(Order order) {
    try{
      int num = orderMapper.updateOrder(order);
      return num>0 ? Result.ofSuccess("修改订单信息成功", num) :
          Result.ofFailed("修改订单信息失败");
    } catch (Exception throwables) {
      System.out.println(throwables.getMessage());
      return Result.ofFailed(throwables.getMessage());
    }
  }
}
